from datetime import datetime

from sqlalchemy import Integer, Column, String, Enum, DateTime, ForeignKey, Float, Text, PrimaryKeyConstraint, text
from sqlalchemy.orm import relationship

from src.extension.extension_db import db
class LearningReport(db.Model):
    """学习报告表模型"""
    __tablename__ = 'learning_reports'
    __table_args__ = (
        PrimaryKeyConstraint('report_id', name='learning_reports_pkey'),
    )

    report_id = Column(Integer, nullable=False, autoincrement=True)
    user_id = Column(Integer, ForeignKey('users.user_id'), nullable=False)
    report_date = Column(DateTime, nullable=False, default=datetime.utcnow)
    total_correct_answers = Column(Integer, nullable=False, default=0)
    total_incorrect_answers = Column(Integer, nullable=False, default=0)
    total_exercises_completed = Column(Integer, nullable=False, default=0)
    average_accuracy = Column(Float, nullable=False, default=0.0)
    detailed_report = Column(Text, nullable=True)
    created_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'))
    updated_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'), server_onupdate=text('CURRENT_TIMESTAMP(0)'))

    user = relationship("User")
